#cloud-config
# Add groups to the system
# Adds the ubuntu group with members 'root' and 'sys'
# and the empty group hashicorp.
groups:
  - ubuntu: [root,sys]
  - 3nets

# Add users to the system. Users are added after groups are added.
users:
  - default
  - name: 3nets
    gecos: 3nets
    shell: /bin/bash
    primary_group: 3nets
    sudo: ALL=(ALL) NOPASSWD:ALL
    groups: users, admin
    lock_passwd: false
    ssh_authorized_keys: "${ssh_key}"
    ssh_file_name: "${ssh_public_key_file}"

# Downloads the golang package
packages:
  - golang-go
  - wireguard
  - wireguard-tools

# Sets the GOPATH & downloads the demo payload
runcmd:
  - sudo su 3nets
  - sudo mkdir /home/3nets/go
  - sudo chown 3nets:3nets /home/3nets/go
  - export GOPATH=/home/3nets/go
  - export HOME=/home/3nets/
  - cd /home/3nets/
  - git clone https://notabug.org/pellucide/gowireguard.git
  - cd /home/3nets/gowireguard/cmd
  - bash build.sh
  - sudo chown -R 3nets:3nets /home/3nets/gowireguard
  - sudo chown -R 3nets:3nets /home/3nets/go
  - sudo ./wireguardEdgeClient &
    

write_files:
  - path: /etc/3nets.conf
    owner: root:root
    permissions: "0644"
    content: "Signature=\"${Signature}\" \nManagerIp=\"${ManagerIp}\"\n"
